package com.ysh.contentcenter.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.ysh.contentcenter.feignclient.TestBaiduFeignClient;
import com.ysh.contentcenter.rocketmq.MySource;
import com.ysh.contentcenter.service.content.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
@RefreshScope
public class TestController {
    @Autowired
    private TestBaiduFeignClient testBaiduFeignClient;

    @GetMapping("/baidu")
    public String baiduIndex(){
       return testBaiduFeignClient.index();
    }

    @Autowired
    private TestService testService;

    @GetMapping("/test-a")
    public String testA(){
        testService.common();
        return "test-a";
    }

    @GetMapping("/test-b")
    public String testB(){
        testService.common();
        return "test-b";
    }

    @GetMapping("/test-hot")
    @SentinelResource("hot")
    public String testHot(@RequestParam(required = false) String a,@RequestParam(required = false) String b){
        return a+" "+b;
    }

    @Autowired
    private Source source;

    @GetMapping("/test-stream")
    public String testStream(){
        this.source.output().send(MessageBuilder.withPayload("消息体").build());
        return "success";
    }


    @Autowired
    private MySource mySource;

    @GetMapping("/test-stream2")
    public String testStream2(){
        this.mySource.output().send(MessageBuilder.withPayload("消息体").build());
        return "success";
    }

    @Value("${your.configuration}")
    private String yourConfiguration;

    @GetMapping("/test-nacos-config")
    public String testNacosConfig(){
        return yourConfiguration;
    }


}
